//
//  MicroAppHeadView.swift
//  TinyUI
//
//  Created by 徐涛 on 2020/3/26.
//  Copyright © 2020 葛晓良. All rights reserved.
//

import UIKit
import TinyUI
enum MicroAppHeadViewType{
    case onlyBig  //只有大标题
    case onlysection  //只有小标题
    case myOverSection  //只有小标题在中间的 说明（）
    case both
}

class MicroAppHeadView: UICollectionReusableView {
    let lblBigTitle=UILabel.init()
    let lblSectionTitle=UILabel.init()
    let bigLblHeight:CGFloat = 30
    let sectionLblHeight:CGFloat = 25
    let myOverSectionLblHeight:CGFloat = 23
    
    var cellType:MicroAppHeadViewType=MicroAppHeadViewType.onlyBig
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        layoutUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    required init!(element: Element!) {
        fatalError("init(element:) has not been implemented")
    }
    
    func layoutUI() {
        lblBigTitle.frame=CGRect(x: 0, y: 0, width: self.bounds.width, height: 30)
        lblBigTitle.textAlignment=NSTextAlignment.center
        lblBigTitle.textColor=UIColor.tyColor(withHex: "#0B0507" )
        lblBigTitle.font=UIFont.boldSystemFont(ofSize: 16.0)
        self.addSubview(lblBigTitle)
        lblSectionTitle.frame=CGRect(x: 10, y: 0, width:  self.bounds.width-10, height: 25)
        lblSectionTitle.textAlignment=NSTextAlignment.left
        lblSectionTitle.textColor=UIColor.tyColor(withHex: "#0B0507" )
        lblSectionTitle.font=UIFont.boldSystemFont(ofSize: 16.0)
        self.addSubview(lblSectionTitle)
        
    }
    
    
    //MARK:-config
    func configHead(params:Dictionary<String,Any>,dependence:NSDictionary) {
        if params["type"] != nil {
            lblSectionTitle.text="\(String(describing: params["type"]!))"
        }
        lblSectionTitle.font=UIFont.boldSystemFont(ofSize: 16.0)
        lblSectionTitle.textAlignment=NSTextAlignment.left
        lblBigTitle.textColor=UIColor.black
        lblSectionTitle.textColor=UIColor.black
        if cellType == MicroAppHeadViewType.onlyBig{
            lblBigTitle.textAlignment=NSTextAlignment.center;
            lblSectionTitle.isHidden=true
            lblBigTitle.isHidden=false
            lblBigTitle.frame=CGRect(x: 0, y: self.bounds.height-bigLblHeight, width: self.bounds.width, height: bigLblHeight)
            if let tColor:String = dependence["title-color"] as? String{
                lblBigTitle.textColor=UIColor.tyColor(withHex: tColor )
            }
        }else if cellType == MicroAppHeadViewType.onlysection{
            lblBigTitle.isHidden=true
            lblSectionTitle.isHidden=false
            lblSectionTitle.frame=CGRect(x: 25, y: (self.bounds.height-sectionLblHeight)/2.0, width: self.bounds.width-25, height: sectionLblHeight)
            if let tColor:String = dependence["section-color"] as? String{
                lblSectionTitle.textColor=UIColor.tyColor(withHex: tColor )
            }else{
                lblSectionTitle.textColor=UIColor.tyColor(withHex: "#0B0507" )
            }
        }else if cellType == MicroAppHeadViewType.myOverSection{
            lblBigTitle.isHidden=true
            lblSectionTitle.isHidden=false
            lblSectionTitle.frame=CGRect(x: 0, y:0, width: self.bounds.width, height: myOverSectionLblHeight)
            lblSectionTitle.font=UIFont.boldSystemFont(ofSize: 13.0)
            if let tColor:String = dependence["tip-text-color"] as? String{
                lblSectionTitle.textColor=UIColor.tyColor(withHex: tColor )
            }else{
                lblSectionTitle.textColor=UIColor.tyColor(withHex: "#999A9A" )
            }
            lblSectionTitle.textAlignment=NSTextAlignment.center
        }else{
            lblBigTitle.isHidden=false
            lblBigTitle.frame=CGRect(x: 0, y: 25, width: self.bounds.width, height: bigLblHeight)
            lblSectionTitle.isHidden=false
            lblSectionTitle.frame=CGRect(x: 10, y:lblBigTitle.frame.origin.y+lblBigTitle.bounds.height+20, width: self.bounds.width-10, height: sectionLblHeight)
        }
        
    }
}
